////////////////////////////////////////////////////////////////////////////////
/// @file    read_sd_card_info.c
/// @author  AE TEAM
/// @brief   THIS FILE PROVIDES ALL THE SYSTEM FUNCTIONS.
////////////////////////////////////////////////////////////////////////////////
/// @attention
///
/// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
/// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
/// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
/// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
/// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
/// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
///
/// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
////////////////////////////////////////////////////////////////////////////////

// Define to prevent recursive inclusion
#define _READ_SD_CARD_INFO_C_

// Files includes
#include <stdio.h>
#include "HAL_conf.h"
#include "HAL_device.h"
#include "uart.h"
#include "delay.h"
#include "sdio.h"
#include "sdio_sdcard.h"

#include "read_sd_card_info.h"
u8 vbuf[512 * 10];
////////////////////////////////////////////////////////////////////////////////
/// @brief  print the SD card information
/// @note   None.
/// @param  None
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void show_sdcard_info(void)
{
    switch(SDCardInfo.CardType) {
        case SDIO_STD_CAPACITY_SD_CARD_V1_1:
            printf("Card Type:SDSC V1.1\r\n");
            break;
        case SDIO_STD_CAPACITY_SD_CARD_V2_0:
            printf("Card Type:SDSC V2.0\r\n");
            break;
        case SDIO_HIGH_CAPACITY_SD_CARD:
            printf("Card Type:SDHC V2.0\r\n");
            break;
        case SDIO_MULTIMEDIA_CARD:
            printf("Card Type:MMC Card\r\n");
            break;
    }
    printf("Card ManufacturerID:%d\r\n", SDCardInfo.SD_cid.ManufacturerID); //The manufacturer ID
    printf("Card RCA:%d\r\n", SDCardInfo.RCA);                              //Card relative address
    printf("Card Capacity:%d MB\r\n", (u32)(SDCardInfo.CardCapacity >> 20));
    printf("Card BlockSize:%d\r\n\r\n", SDCardInfo.CardBlockSize);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief  read SD card information
/// @note   None.
/// @param  None
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void read_sd_card_info(void)
{
    u16 i = 5;
    SD_Error result;
    u32 sd_size;

    SDIO_ConfigInit();
    printf("SDCARD TEST\r\n");
    while(1) {

        result = SD_Init();

        if(result == SD_OK) {
            break;
        }
        printf("SD Card Error!\r\n");

        DELAY_Ms(1);
    }
    show_sdcard_info();
    i = 5;
    while(i--) {
        if(SD_ReadDisk(&vbuf[0], 0, 1) == 0) { //read Section 0 data
            printf("UART Sending Data...\r\n");
            printf("SECTOR 0 DATA:\r\n");
            for(sd_size = 0; sd_size < 512; sd_size++) {
                printf("%02x ", vbuf[sd_size]);
            }
            printf("\r\nDATA ENDED\r\n");
            printf("UART Send Data Over!\r\n");
        }
        DELAY_Ms(50);
    }
}



/// @}

/// @}

/// @}

